<template>
  <!-- 固定资产折旧费详情 -->
   <!-- {
        text: '导出',
        type: 'info',
        icon: 'export',
        trigger: 'export',
      },
      {
        text: '打印',
        type: 'info',
        trigger: 'print',
      }, -->
  <Drawer
    title="固定资产折旧费详情"
    :visible="FixedAssetsDetailsVisible"
    :header-color="'#e7ecf8'"
    width="80%"
    :footer-btns="[
      {
        text: '取消',
        type: 'info',
        trigger: 'cancel',
      },
    ]"
    @cancel="cancel"
    @print="print"
    @export="exportBtn"
  >
    <div class="drawer-box">
      <!-- <div class="box-title">固定资产折旧费详情</div> -->
      <div class="box-table">
        <el-table
          ref="tableref"
          v-loading="tableLoading"
          :data="tableGdzcData"
          border
          :header-cell-style="{
            background: '#fafafa',
            borderColor: '#e7ecf8',
            color: '#555555',textAlign:'center'
          }"
          header-row-class-name="ck-table-header"
          row-class-name="ck-table-row"
          size="small"
          height="100%"
          style="width: 100%"
          show-summary
          :summary-method="getSummaries"
        >
          <el-table-column
            align="center"
            type="index"
            label="序号"
            width="60"
          />
          <el-table-column prop="deptcode" label="核算单元代码" />
          <el-table-column prop="deptname" label="核算单元名称" />
          <!-- <el-table-column prop="costitemcode" label="成本项目编码" /> -->
          <!-- <el-table-column prop="costitemname" label="成本项目名称" /> -->
          <el-table-column prop="cardnum" label="固定资产编码" />
          <el-table-column prop="cardname" label="固定资产名称" />
          <el-table-column prop="usestartdate" label="启用日期" />
          <!-- <el-table-column prop="originalvalue" label="原值" />
          <el-table-column prop="monthlimit" label="折旧月段" /> -->
          <el-table-column prop="value" label="折旧额"  align="right">
            <template slot-scope="scope">
              {{ scope.row.value |numberToCurrency}}
            </template>
          </el-table-column>
        </el-table>
        <!-- <div class="pagenation-box">
          <el-pagination
            :current-page.sync="currentPage"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div> -->
      </div>
    </div>
  </Drawer>
</template>
<script>
export default {
  props: {
    // 接收父组件传来的值
    FixedAssetsDetailsVisible: Boolean,
    tableGdzcData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      total: 0,
      pageSize: 20,
      currentPage: 1,
      tableLoading: false,
    };
  },
  mounted() {},
  updated() {
    if (this.$refs.tableref) {
      this.$refs.tableref.doLayout();
    }
  },
  methods: {
    // 关闭抽屉
    cancel() {
      this.$emit("fixedAssetsDetails", { fixedAssetsDetailsVisible: false });
    },
    // 导出
    exportBtn() {
      console.log("导出");
    },
    // 打印
    print() {
      console.log("打印");
    },
    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this._getData();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this._getData();
    },
    // 指定列求和
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (index >= 6) {
          if (!values.every((value) => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] = sums[index].toFixed(2);
            // sums[index] += " 元";
          } else {
            sums[index] = "N/A";
          }
        }
      });
      return sums;
    },
  },
};
</script>
<style lang="less" scoped>
.el-table--mini,
.el-table--small,
.el-table__expand-icon {
  font-size: 14px !important;
}

.ck-table-header {
  th {
    background: #fafafa !important;
    height: 48px;
    color: #555555 !important;
  }
}
.pagenation-box {
  display: flex;
  padding-top: 2px;
  justify-content: flex-end;
}
.drawer-box {
  height: 100%;
}
.box-title {
  height: 44px;
  background: #f6f9fe;
  border-bottom: 1px solid #e7ecf8;
  font-size: 16px;
  color: #555555;
  line-height: 44px;
  padding-left: 10px;
  box-sizing: border-box;
}
.box-table {
  padding: 14px 10px 14px 10px;
  height: 100%;
  box-sizing: border-box;
}
</style>
